<template>
	<div class="newsinfo-container">
		<h3 class="title">{{ newsinfo.title }}</h3>
		<p class="subtitle">
			<span>来源：{{  newsinfo.source }} 发表时间:{{ newsinfo.ptime | dateFormat}}</span>
			<span>点击：{{ newsinfo.tcount }}次</span>
		</p>
		<hr>
		<div class="content">
			<!-- 图集 -->
			<div v-if="newsinfo.picInfo" v-for="item in newsinfo.picInfo" :key="item.id"> 
				<img :src="item.url" alt="">
			</div>
			<!-- 详情 -->
			{{ newsinfo.digest }}
		</div>
		
		<!-- 评论区域-->
		<comment-box :id="this.id"></comment-box>
	</div>
</template>

<script>
	import { Toast } from 'mint-ui'
	import comment from '../subcomponents/Comment.vue'
	export default {
		data(){
			return {
				id:this.$route.params.id,
				newsinfo:{}
			}
		},
		methods:{
			getNewsInfo(){ // 获取新闻详情
				this.$http.get('https://www.apiopen.top/journalismApi').then(result => {
					if(result.body.code === 200){
						var temp = result.body.data.ent
						for(var i=0; i<temp.length; i++){
							if(temp[i].docid === this.id){
								this.newsinfo = temp[i]
								break
							}
						}
					}else{
						Toast('新闻详情获取失败！')
					}
					
				})
			}
		},
		components:{
			'comment-box':comment
		},
		created(){
			this.getNewsInfo()
		}
	}
</script>

<style lang="less" scoped="scoped">
	.newsinfo-container{
		padding: 4px;
		.title{
			font-size: 16px;
			text-align: center;
			margin: 6px 0;
		}
		.subtitle{
			font-size: 12px;
			display: flex;
			justify-content: space-between;
		}
		.content{
			img{
				width: 100%;
			}
		}
	}
</style>
